﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using DomainModel.Entities;
using NHibernate;
using System.Reflection;
using System.IO;

namespace SchemaExportTest
{
    public class Program
    {
        private static Configuration _cfg;
        [SetUp]
        public static void Main(string[] args)
        {
            //_cfg = new Configuration().AddProperties(new Dictionary<string, string>() { { "connection.connection_string", "Data Source=.\\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True;Pooling=False" } });
            //_cfg = new Configuration().AddProperties(new Dictionary<string, string>() { { "connection.connection_string", "Data Source=192.168.0.223;Initial Catalog=tttt;Persist Security Info=True;User ID=sa;Password=bitauto123!" } });
            _cfg = new Configuration();
            //Stream rsrc = typeof(DomainModel.Entities.Customer).Assembly.GetManifestResourceStream("DomainModel.Mappings.DomainModel.Entities.Customer.hbm.xml");
            
            _cfg.Configure();
            _cfg.AddClass(typeof(Customer1));
            //_cfg.AddAssembly("DomainModel");
            //Insert(_cfg.BuildSessionFactory().OpenSession());
            CreateTest();
            Console.ReadLine();
        }

        public static void Insert(ISession seesion)
        {
            Customer c = new Customer() { Firstname = "1", Lastname = "2", Version = 1 };
            seesion.Save(c);
            seesion.Flush();
        }

        [Test]
        public static void DropTest()
        {
            var export = new SchemaExport(_cfg);
            export.Drop(true, true);
        }

        [Test]
        public static void CreateTest()
        {
            //var export = new SchemaExport(_cfg);
            var export = new SchemaUpdate(_cfg);
            //export.Create(true, true);
            export.Execute(true,true);
        }
    }
}
